function mix = initialiseGMM(data, covar_type, kmax, initMode)


[N D] = size(data);

mix.type = 'gmm';
mix.nin = D;
mix.covar_type = covar_type;
mix.ncentres = kmax;

switch initMode
    case {1}
        randindex = round(1:(N/kmax):N);
    case {2}
        randindex = round(1:(N/kmax):N);
        randindex = randindex(randperm(kmax));
    case {3}
        randindex = randperm(N);
        randindex = randindex(1:kmax);
    otherwise
        error('bah')
end

mix.centres = data(randindex, :);
mix.priors = (1/kmax)*ones(1,kmax);
cov_data = cov(data);
for k=1:kmax
%     mix.covars(:, :, k) = diag(diag(cov(data))/ (10*D));
%     mix.covars(:, :, k) = diag(ones(1, D)*max(diag(cov(data)/10)));
%     mix.covars(:, :, k) = eye(D) * (trace(cov_data)/ (10*D));

    mix.covars(:,:,k) = eye(D) * (trace(cov_data)/ (10*D)) + eye(D)*0.000001;
end
